package com.example.t1;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class MyService extends Service {
    MediaPlayer bgmPlayer = null;
    public MyService() {
    }

    @Override
    public void onCreate() {

        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(bgmPlayer==null){
            bgmPlayer = MediaPlayer.create(this,R.raw.merrychristmas);
            if(!bgmPlayer.isLooping())
                bgmPlayer.setLooping(true);
            bgmPlayer.start();
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        if(bgmPlayer!=null){
            bgmPlayer.release();
        }

        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
